package com.kuhyygy.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button; 
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.kuhyygy.R;
import com.kuhyygy.uitl.ActivityCollector;

public class ProperActivity extends BaseActivity {
	
	private Button saveBtn;
	private Button readBtn;
	private EditText name;
	private EditText page;
	private TextView propView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.myproper);
		saveBtn = (Button) this.findViewById(R.id.saveProp);
		readBtn = (Button) this.findViewById(R.id.readProp);
		name = (EditText) this.findViewById(R.id.menuName);
		page = (EditText) this.findViewById(R.id.toPage);
		propView = (TextView) this.findViewById(R.id.propView);
		
		saveBtn.setOnClickListener(l);
		readBtn.setOnClickListener(l);
	}
	
	private OnClickListener l = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			SharedPreferences sp = ProperActivity.this.getSharedPreferences("QQGame", Context.MODE_PRIVATE);
			switch (v.getId()) {
			case R.id.saveProp:
				Editor e = sp.edit();
				e.putString("menuName", name.getText().toString());
				e.putString("toPage", page.getText().toString());
				e.commit();
				Toast.makeText(ProperActivity.this, "菜单保存成功", Toast.LENGTH_SHORT).show();
				break;
			case R.id.readProp:
				String name = sp.getString("name", "kuhyyg");
				int age = sp.getInt("age", 12);
				String mz = sp.getString("mazi", "麻吱");
				propView.setText("name:" + name + " --- age:" + age + " --- mazi:" + mz);
				break;
			default:
				break;
			}
		}
	};
	
	/**
	 * 菜单加载
	 */
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	};

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.personalSetting:
			break;
		case R.id.exit:
			ActivityCollector.removeAll();
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
}
